var path = require('path')
var webpack = require('webpack')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')

module.exports = {
  devtool: 'source-map',
  entry: {
    bundle: ['babel-polyfill', path.resolve(__dirname, 'app/index.js')],
    vendor: ['vue', 'atelement', 'vue-router', 'vuex', 'axios', 'less', 'file-saver']
  },
  plugins: [
    new webpack.optimize.CommonsChunkPlugin({
      name: 'vendor',
      children: true,
      async: true,
      // (create an async commons chunk)
      minChunks: 3
      // filename: '[name].js'
    }),
    new UglifyJsPlugin({
      uglifyOptions: {
        compress: {
          warnings: false,
          drop_debugger: true,
          drop_console: true
        }
      } }),
    new webpack.HotModuleReplacementPlugin()
  ],
  output: {
    path: path.resolve(__dirname, 'build'),
    filename: '[name].js'
    // libraryTarget:"window",
    // library :"saas"
  },
  devServer: {
    historyApiFallback: true,
    hot: true,
    inline: true,
    stats: {
      colors: true
    },
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:9000',
        changeOrigin: true
      }
    }
  },
  module: {
    loaders: [
      // {
      //     test: /\.(js|vue)$/,
      //     loader: 'eslint-loader',
      //     enforce: 'pre',
      //     options: {
      //       formatter: require('eslint-friendly-formatter')
      //     }
      // },
      {
        test: /\.worker\.js$/,
        use: {
          loader: 'worker-loader'
        }
      },
      {
        loader: 'babel-loader?cacheDirectory',
        exclude: [path.resolve(__dirname, 'node_modules')],
        include: [path.resolve(__dirname, 'app')],
        test: /\.(js)$/,
        query: {
          presets: ['es2015', 'stage-0']
        }
      },
      {
        test: /\.vue$/,
        include: [path.resolve(__dirname, 'app')],
        exclude: [path.resolve(__dirname, 'node_modules')],
        loader: 'vue-loader'
      },
      {
        test: /\.(png|jpg|gif)$/,
        loader: 'url-loader?limit=250'
      },

      {
        test: /\.css$/,
        loader: 'style-loader!css-loader'
      },
      {
        test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
        loader: 'url-loader?limit=10000&mimetype=application/font-woff'
      },
      {
        test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
        loader: 'url-loader?limit=10000&mimetype=application/font-woff2'
      },
      {
        test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
        loader: 'url-loader?limit=10000&mimetype=application/octet-stream'
      },
      {
        test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
        loader: 'file-loader'
      },
      {
        test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
        loader: 'url-loader?limit=10000&mimetype=image/svg+xml'
      }
    ]
  },
  resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      components: path.resolve(__dirname, 'app/components'),
      utils: path.resolve(__dirname, 'app/utils')
    }
  }
  // plugins: [
  //     new webpack.HotModuleReplacementPlugin() // Enable HMR
  // ],
}
